<template>
	<view>
		<uni-search-bar @input="search" placeholder="搜索账号名称" bgColor="#EEEEEE" />
		<view class="list">
			<view class="flex align list-item between" v-for="(item,index) in list" :key="index" @click="toNav(item.id)">
				<view class="flex align">
					<image src="../../static/images/manage/icon.png"></image>
					<view class="item-name">{{item.name}}</view>
				</view>
				<uni-icons type="right" size="15" color="grey"></uni-icons>

			</view>
			<uni-load-more :status="status" v-if="!empty" :content-text="loadText"></uni-load-more>
			<xw-empty :isShow="empty" text="暂无数据" textColor="#777777"></xw-empty>
		</view>
	</view>
</template>

<script>
	import {
		companyLists,
		companyEnter
	} from '@/api/apiData.js';
	export default {
		data() {
			return {
				name:'',
				list:[],
				totalPage: 1,
				page: 0,
				offset: 30,
				list: [],
				scrollTop: 0,
				empty: false,
				loadText: {
					loadmore: '点击或上拉加载更多',
					loading: '努力加载中',
					nomore: '实在没有了'
				},
				status: 'loadmore',
			};
		},
		onLoad() {
			this.getlist()
		},
		onShareAppMessage(res) {
		
		},
		methods:{
			search(e){
				this.name = e
				this.page = 0
				this.list = []
				this.getlist();
			},
			async getlist() {
				const that = this;
				const {
					totalPage,
					page,
					offset,
					list,
					name
					// channel_id,
				} = that;
				
				let obj = {
					size: offset,
					page: page + 1,
					name
				};
				if(obj.task_type==1){
					obj.status = ''
				}
				that.status = 'loading';
				if (totalPage > page) {
					let result = await companyLists(obj);
					if (result.code == 1) {
						that.page = page + 1;
						if (result.data.total == 0) {
							console.log((888))
							that.empty = true;
							that.status = 'nomore';
							return;
						}
						that.empty = false;
						setTimeout(() => {
							that.status = 'loadmore';
						}, 500);
						that.list = list.concat(result.data.list);
						that.totalPage = Math.ceil(result.data.total / offset);
					}
				} else {
					setTimeout(() => {
						that.status = 'nomore';
					}, 500);
				}
			},
			async toNav(id){
				const result = await companyEnter({
					id:id
				})
				if(result.code==1){
					uni.setStorageSync('token2', result.data.token);
					uni.navigateTo({
						url:'/pages/manage/manage'
					})
				}
				// uni.navigateBack()
			}
		}
	}
</script>

<style lang="scss" scoped>
.list{
	margin: 30rpx;
	.list-item{
		border: solid 1rpx gainsboro;
		border-radius: 10rpx;
		padding: 20rpx 15rpx;
		margin-bottom: 20rpx;
		image{
			width: 30rpx;
			height: 30rpx;
			margin-right: 15rpx;
		}
	}
}
</style>
